<template>
  <!--<ContentWrap>-->
  <!--  &lt;!&ndash; 搜索工作栏 &ndash;&gt;-->
  <!--  <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true">-->
  <!--    <el-form-item :label="t('pickBatch.fields.batchName')" prop="batchName">-->
  <!--      <el-input-->
  <!--        v-model="queryParams.batchName"-->
  <!--        :placeholder="t('common.inputTextPlaceholder') + t('pickBatch.fields.batchName')"-->
  <!--        clearable-->
  <!--        @keyup.enter="handleQuery"-->
  <!--        class="!w-240px"-->
  <!--      />-->
  <!--    </el-form-item>-->
  <!--    <el-form-item>-->
  <!--      <el-button @click="handleQuery">-->
  <!--        <Icon icon="ep:search" class="mr-5px" />{{ t('common.search') }}-->
  <!--      </el-button>-->
  <!--      <el-button @click="resetQuery">-->
  <!--        <Icon icon="ep:refresh" class="mr-5px" />{{ t('common.reset') }}-->
  <!--      </el-button>-->
  <!--    </el-form-item>-->
  <!--  </el-form>-->
  <!--</ContentWrap>-->

  <!-- 列表 -->
  <ContentWrap>
    <vxe-toolbar ref="toolbarRef" custom />
    <vxe-table
      id="iPickBatch-table"
      ref="tableRef"
      v-loading="loading"
      :data="list"
      stripe
      :custom-config="vxeTableConfig"
      :column-config="{ resizable: true }"
      :size="vxeTableSize"
    >
      <vxe-column :title="t('common.index')" type="seq" field="seq" width="60" align="center" />
      <vxe-column
        :title="t('mentorPickReview.fields.batchName')"
        field="batchName"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      />
      <vxe-column
        :title="t('mentorPickReview.fields.year')"
        field="year"
        align="center"
        show-header-overflow
        show-overflow
        min-width="50"
      />
      <vxe-column
        :title="t('mentorPickReview.fields.reviewStartTime')"
        field="reviewStartTime"
        align="center"
        show-header-overflow
        show-overflow
        min-width="120"
        :formatter="vxeDateFormatter"
      />
      <vxe-column
        :title="t('mentorPickReview.fields.reviewEndTime')"
        field="reviewEndTime"
        align="center"
        show-header-overflow
        show-overflow
        min-width="120"
        :formatter="vxeDateFormatter"
      />
      <vxe-column
        :title="t('mentorPickReview.fields.applyCount')"
        field="applyCount"
        align="center"
        show-header-overflow
        show-overflow
        min-width="60"
      />
      <vxe-column
        :title="t('mentorPickReview.fields.voteCount')"
        field="voteCount"
        align="center"
        show-header-overflow
        show-overflow
        min-width="60"
      />
      <vxe-column
        :title="t('mentorPickReview.fields.waitVoteCount')"
        field="waitVoteCount"
        align="center"
        show-header-overflow
        show-overflow
        min-width="60"
      />
      <vxe-column
        :title="t('common.operate')"
        field="operator"
        align="center"
        fixed="right"
        width="200"
      >
        <template #default="{ row }">
          <el-button link type="primary" @click="handleClick(row.batchId)">
            {{ t('mentorPickReview.operate.reviewScene') }}
          </el-button>
        </template>
      </vxe-column>
    </vxe-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>

<script setup lang="ts">
import { vxeDateFormatter } from '@/utils/formatTime'
import { MentorPickReviewApi, MentorPickReviewVO } from '@/api/recruit/mentorPickReview'
import type { VxeTablePropTypes, VxeToolbarInstance, VxeTableInstance } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'

/** 评审导师遴选批次 列表 */
defineOptions({ name: 'MentorPickReview' })

const { t } = useI18n() // 国际化
const router = useRouter(); // 路由

const toolbarRef = ref<VxeToolbarInstance>()
const tableRef = ref<VxeTableInstance>()

const loading = ref(true) // 列表的加载中
const list = ref<MentorPickReviewVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  batchName: undefined
})
const queryFormRef = ref() // 搜索的表单

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await MentorPickReviewApi.getPickBatchPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  ;(queryParams as any).advanced = undefined
  handleQuery()
}

// 点击评审现场
const handleClick = (id: string) => {
  router.push({
    path: `/recruit/review-scene/${id}`
  })
}

/** 初始化 **/
onMounted(() => {
  getList()

  const table = tableRef.value
  const toolbar = toolbarRef.value
  if (table && toolbar) {
    table.connect(toolbar)
  }
})
</script>
